package cn.itcast.order;

import com.alibaba.cloud.nacos.ribbon.NacosRule;
import com.netflix.loadbalancer.IRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
@EnableFeignClients(basePackages = {"cn.itcast.feign.clients"})//扫描所有Feign接口类
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    /**
     * 注册RestTemplate实例，方便调用http接口
     * @return
     */
    @Bean
    @LoadBalanced//开启ribbon负载均衡机制
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }


    //修改负载均衡策略（修改）
    @Bean
    public IRule rule(){
        return new NacosRule();//集群优先
    }

}